package com.xtoad.ecms.common.utils;

import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 密码加密解密辅助类
 *
 * @author xtoad
 * @date 2021/1/9
 */
public class PasswordUtils {

    private static PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();

    /**
     * 密码加密
     *
     * @param raw String 原始密码
     * @return String 加密后的密码
     */
    public static String encode(String raw) {
        return passwordEncoder.encode(raw);
    }

    /**
     * 密码校验
     *
     * @param raw            String 原始密码
     * @param encodePassword String 加密后的密码
     * @return true | false
     */
    public static boolean matches(String raw, String encodePassword) {
        return passwordEncoder.matches(raw, encodePassword);
    }
}
